//
//  industryClassificationVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/5/26.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "industryClassificationVC.h"
#import "industryClassificationCell.h"
#import "SearchProject.h"

static NSString * cellId = @"cellId";
@interface industryClassificationVC ()
@property (strong, nonatomic) NSArray *labelArr;
@property (strong, nonatomic) NSArray *imgArr;
@property (strong, nonatomic) NSDictionary *dataDict;
@end

@implementation industryClassificationVC
#pragma mark - 初始化
-(NSDictionary *)dataDict{
    if (!_dataDict) {
        _dataDict = [NSDictionary dictionary];
    }
    return _dataDict;
}

-(NSArray *)labelArr{
    if (!_labelArr) {
        _labelArr = @[@"市政基建",@"房地产业",@"交通运输",@"建筑建材",@"信息软件",@"金融",@"教育",@"现代服务",@"医药",@"旅游休闲",@"生态环保",@"制造业",@"水电燃气",@"文体娱乐",@"社会保障",@"农林牧渔",@"批发零售",@"矿产冶金"];
    }
    return _labelArr;
}

-(NSArray *)imgArr{
    if (!_imgArr) {
        _imgArr = @[@"生物医药",
                    @"旅游休闲",
                    @"制造业",
                    @"批发零售",
                    @"房地产业",
                    @"交通运输",
                    @"矿产冶金",
                    @"建筑建材",
                    @"信息软件",
                    @"金融",
                    @"教育",
                    @"现代服务",
                    @"生态环保",
                    @"市政基建",
                    @"文体娱乐",
                    @"社会保障",
                    @"水电燃气",
                    @"农林牧渔", ];
    }
    return _imgArr;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    [self sendRequest];

}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"行业分类";
    
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"Back" highImage:@"Back"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    self.tableView.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1];
    
    // 注册
    UINib * nib = [UINib nibWithNibName:@"industryClassificationCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:cellId];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}

-(void)leftBarButtonItemClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.labelArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    industryClassificationCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId forIndexPath:indexPath];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    
    NSArray *labelArr = self.dataDict[@"industryName"];
    NSArray *sumMoneyArr = self.dataDict[@"sumMoney"];
    NSArray *sumNumber = self.dataDict[@"sumNumber"];
    
    float money = [sumMoneyArr[indexPath.section] floatValue]/100000000;
    
    cell.detail.text = [NSString stringWithFormat:@"项目数量%@，项目金额%.2f亿",sumNumber[indexPath.section],money];
    cell.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1];
    cell.headImg.image = [UIImage imageNamed:self.imgArr[indexPath.section]];
    cell.title.text = labelArr[indexPath.section];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];//取消选中状态
    
    UIStoryboard *sb=[UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    
    SearchProject * searchVC = [sb instantiateViewControllerWithIdentifier:@"SearchProject"];
    
    searchVC.searchStr = self.imgArr[indexPath.section];
    
//    searchVC = [sb instantiateViewControllerWithIdentifier:@"SearchProject"];

    [self.navigationController pushViewController:searchVC animated:YES];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 1;
}

#pragma mark - 请求数据
-(void)sendRequest{
    
    // 请求数据
    NSDictionary * dic = [NSDictionary dictionary];
    [LSHttpTool sendHttpData:@"getSumNumberMoney_app_user.im" params:dic success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];

        self.dataDict = dicInfo[@"data"];
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:@"网络连接错误"];

    }];
    
}
@end
